package constellation.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

import androidx.fragment.app.Fragment;

import com.example.myapplication.R;

import java.util.List;

import constellation.Activity.ParntnerInfoActivity;
import constellation.util.StartInfo;

/**
 * A simple {@link Fragment} subclass.
 */
public class parnterFragment extends Fragment {

    private Spinner spinner1;
    private Spinner spinner2;
    private Button parnternButton;
    Context context;
    View view;
    String []data;
    ArrayAdapter <String>arrayAdapter;
    public parnterFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.fragment_parnter, container, false);
        context=getContext();
        initView();
        Bundle bundle = getArguments();
        StartInfo starInfo = (StartInfo) bundle.getSerializable("info");
        List<StartInfo.StarinfoBean> list = starInfo.getStarinfo();  //数据源
        data=new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            data[i]=list.get(i).getName();
        }
        arrayAdapter=new ArrayAdapter<String>(context,android.R.layout.simple_list_item_1,data);
        spinner1.setAdapter(arrayAdapter);
        spinner2.setAdapter(arrayAdapter);
        parnternButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String cc=spinner1.getSelectedItem().toString();
                startActivity(new Intent(context, ParntnerInfoActivity.class)
                        .putExtra("man",spinner1.getSelectedItem().toString())
                .putExtra("woman",spinner2.getSelectedItem().toString()));
            }
        });
        return view;

    }

    private void initView() {
        spinner1 = (Spinner) view.findViewById(R.id.spinner1);
        spinner2 = (Spinner) view.findViewById(R.id.spinner2);
        parnternButton = (Button) view.findViewById(R.id.parntern_button);
    }
}
